import JSEncrypt from "jsencrypt";
/**
 * 加密公钥 
*/
const PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCJy0OlTMzJ92y5cjgr6yIUkRaD/U5qu215jrGGOxVFMSDA6kl+SGJhLvspjDk9iQ6S0EY1o4IMRiZyI/xQJooflwXon5KOy9MIRxowrFDnMqQv2w2rIKAAB1PE551fqc4STNpYcFoYEx+Dv3XDZShHGD0E7NKcsio485l0aH+VDwIDAQAB";

/**
* 解密私钥
*/
const PRIVATE_KEY = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAInLQ6VMzMn3bLlyOCvrIhSRFoP9Tmq7bXmOsYY7FUUxIMDqSX5IYmEu+ymMOT2JDpLQRjWjggxGJnIj/FAmih+XBeifko7L0whHGjCsUOcypC/bDasgoAAHU8TnnV+pzhJM2lhwWhgTH4O/dcNlKEcYPQTs0pyyKjjzmXRof5UPAgMBAAECgYEAhK2z9PZ+OfqENgxFCgTeS+9oPq8pUpwmTWWYiidZ08X6Q8dT/MS19d3G+bqLYzUVU0g4Um2eSzNA0abUzFhPpaukQCXp2a+o47obxjArmbi5xJ8Rp/i4lwTkB/XOg6tMCZ4bdFOCnJRNu02dGysBdqslYsGvXl5UguRd+SaFMAECQQDhEEguEBFInjYPkFbOhOOOwYOPPXpqn4LUJ/85PIFCV/+mWfjb/v2162iobvMYmow1Re757aabi+P6LJr2doARAkEAnLwR3NQEa085q1ZxL2FDn2SAUSzZ82c9mXy55I0IfXdqfuL1t7P2cQYWTjrVt+0jmR10jpoOcD7pQTXyWifjHwJBALtDkutQzzC/A3hbvv7DL5xeg5qxqqQA6Rih1wjGwT50ffDqN9jFCFFP+Jr9BiRYo4TIFZm7Fb+i3CQS7TVZUCECQGw/nBqnN9IhapQCZLOzem/IirMFxhXMtQef1AecvENjSWMPP2O74DYZXSh0jAy2tIJYjJq8ncI6QQEv0A0iRUMCQCGGElck9kRJ+gwaHdMCLw4U9F8xgiYeMESOD6HimdEJpbC5sywgrZlEj4Pbdaffu8KzehB1HRYPX75KNutkz0c=";

/**
 * 加密方法 
 */
export async function setEncryptData(data) {
    const encryptor = new JSEncrypt();
    encryptor.setPublicKey(PUBLIC_KEY); // 设置公钥
    let rsaDta = encryptor.encrypt(JSON.stringify(data)); // 进行加密
    return rsaDta;
}

/**
 * 加密方法 
 */
export async function setEncryptStrData(data) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(PUBLIC_KEY); // 设置公钥
  let rsaDta = encryptor.encrypt(data); // 进行加密
  return rsaDta;
}

/**
 * 解密方法 
 */
export async function getDecryptData(rsaDta) {
    const decryptor = new JSEncrypt();
    decryptor.setPrivateKey(PRIVATE_KEY); // 设置私钥
    let data = decryptor.decrypt(rsaDta); // 进行解密
    return JSON.parse(data);
}
